<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style type="text/css">
		canvas{
			border: 1px solid #000;
			background: url(images/bg.png);
		}
	</style>
</head>
<body>
	<canvas id="canvas" width="800" height="500"></canvas>
	<script type="text/javascript">
		//得到标签
		var canvas = document.getElementById("canvas");
		//上下文
		var ctx = canvas.getContext("2d");

		ctx.save();		//保存当前上下文
		ctx.translate(100,100);
		ctx.fillRect(200, 200, 100, 100);
		ctx.restore();	//恢复当前上下文

		ctx.fillRect(100,100,100,100);
	</script>
</body>
</html>